package com.yunhe.tianhe.rentcars.controller.zuche;


import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dto.JSONResponse;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.XinXi;
import com.yunhe.tianhe.rentcars.entity.client.Client;
import com.yunhe.tianhe.rentcars.entity.client.ClientCompany;
import com.yunhe.tianhe.rentcars.entity.system.Dept;
import com.yunhe.tianhe.rentcars.entity.zuche.CarOrder;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.PriceService;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.XinXiService;
import com.yunhe.tianhe.rentcars.service.client.ClientService;
import com.yunhe.tianhe.rentcars.service.system.DeptService;
import com.yunhe.tianhe.rentcars.service.zuche.CarOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/order")
public class CarOrderController {

    @Autowired
    private CarOrderService carOrderService;

    @Autowired
    private XinXiService xinXiService;

    @Autowired
    private ClientService clientService;

    @Autowired
    private PriceService priceService;

    @Autowired
    private DeptService deptService;

    @RequestMapping("/djMsg")
    @ResponseBody
    public JSONResponse dj1(Client client, ClientCompany clientCompany, HttpServletRequest request){
        String mobile = client.getMobile();
        Client byMobile = clientService.findOneByMobile(mobile);
        if(byMobile!=null){
            Double discount = byMobile.getDiscount();
            request.getSession().setAttribute("discount",discount);
        }
//        clientService.save(client,clientCompany);

        request.getSession().setAttribute("mobile",mobile);
        return JSONResponse.success("请求成功！");

    }



    @RequestMapping("/dj2")
    public String dj2(HttpServletRequest request){
        List<Dept> list = deptService.findList();
        for(Dept a:list){
            a.setDeptName(a.getInCity()+a.getAddress());
        }
        request.getSession().setAttribute("dept",list);
        return "/zuche/dj2";
    }

















   @RequestMapping("/list")
   @ResponseBody
   public Pageable<XinXi> carMsgList(CarOrder carOrder, Integer offset, Integer limit, HttpServletRequest request){
        request.getSession().setAttribute("carorder",carOrder);
       Pageable page = xinXiService.Zuche(offset, limit);
       return page;
    }











    @RequestMapping("/orderlist")
    @ResponseBody
    public Pageable<CarOrder> orderPageable(Integer offset,Integer limit,String mobile,Long orderid){
        Pageable<CarOrder> orderPageabl = carOrderService.findPage(offset, limit,mobile,orderid);
        return orderPageabl;
    }

    @RequestMapping("/shou")
    public String shou(){
        return "/zuche/shou";
    }



    @RequestMapping("/yd2")
    public String yd2(){
        return "/zuche/yd2";
    }

    @RequestMapping("/yu")
    public String yu(){
        return "/zuche/yu";
    }

    @RequestMapping
    public String index(){
        return "index";
    }


}
